<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSocketTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //用户的ws链接状态和对应的链接id号
        Schema::create('user_socket_session', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('client_id')->comment('链接编号');
            $table->unsignedBigInteger('user_id')->comment('用户id号');
            $table->foreign('user_id')->references('id')->on('user');
            $table->boolean('status')->comment('链接状态 0关闭中 1链接中');
            $table->timestamps();
        });


        //商家的ws链接状态和对应的链接id号
        Schema::create('business_socket_session', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('client_id')->comment('链接编号');
            $table->unsignedBigInteger('user_id')->comment('用户id号');
            $table->foreign('user_id')->references('id')->on('business');
            $table->boolean('status')->comment('链接状态 0关闭中 1链接中');
            $table->timestamps();
        });

        //用户消息和消息是否已经通知到位
        Schema::create('user_message', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id')->comment('id号');
            $table->unsignedBigInteger('num')->comment('消息对应的订单号')->default(null);
            $table->foreign('user_id')->references('id')->on('user');
            $table->string('message')->comment('通知的消息')->default(null);
            $table->tinyInteger('message_code')->comment('预定义好了的消息代码');
            $table->boolean('is_confirm')->comment('消息是否已经通知到位')->default(0);
            $table->timestamps();
        });


        //商家消息和消息是否已经通知到位
        Schema::create('business_message', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id')->comment('id号');
            $table->unsignedBigInteger('num')->comment('消息对应的订单号')->default(null);
            $table->foreign('user_id')->references('id')->on('business');
            $table->string('message')->comment('通知的消息')->default(null);
            $table->tinyInteger('message_code')->comment('预定义好了的消息代码');
            $table->boolean('is_confirm')->comment('消息是否已经通知到位')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('business_message');
        Schema::dropIfExists('user_message');
        Schema::dropIfExists('business_socket_session');
        Schema::dropIfExists('user_socket_session');
    }
}
